package com.frame.work.frame.deal.device0fac;

import com.alibaba.fastjson.JSONObject;
import com.frame.work.common.util.JsonToMqtt;
import com.frame.work.frame.deal.base.BaseFrame;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 *空调面板
 */
@Data
public class KongTiaoMianBan_0FAC0202 extends BaseFrame{

    private String switchState;
    public KongTiaoMianBan_0FAC0202(String gatewayMac, String data){

        //将基础数据进行处理
        super(gatewayMac,data);

        ////开关状态
        this.setSwitchState( StringUtils.substring(data,data.length() - 18, data.length()-16));
        //锁定状态
        String lock = StringUtils.substring(data,data.length() - 16, data.length() - 14);
        //工作模式
        String mode = StringUtils.substring(data,data.length() - 8, data.length() - 6);
        //风速设置
        String speed = StringUtils.substring(data,data.length() - 6, data.length() - 4);
        //当前温度
        String actualTemp = StringUtils.substring(data,data.length() - 14, data.length()- 10);
        float actualTemp1 = Float.parseFloat(StringUtils.substring(actualTemp,2, 4) + '.' + StringUtils.substring(actualTemp,0, 2));
        //温度设置
        String temperature = StringUtils.substring(data,data.length() - 2, data.length());

        if ("FF".equals(temperature)) {
            temperature="26";
        }
        String position = "";
        //将actions信息放入json对象中
        Map <String,Object> actions = new HashMap();
        actions.put("switchState",switchState);
        actions.put("lock",lock);
        actions.put("mode",mode);
        actions.put("speed",speed);
        actions.put("temperature",temperature);
        actions.put("position",position);
        actions.put("actualTemp",String.valueOf(actualTemp1));
        this.setActions(actions);

        //处理好的json对象
        String json = JSONObject.toJSONString(this);
        //将数据发送到mqtt队列中
        JsonToMqtt.sendMQTT(gatewayMac,json);

    }

}
